<?php
include("include/config.inc.php");

if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	if(isset($_GET['pmMasterId']) && $_GET['pmMasterId'] > 0)
	{
		$selectData = "SELECT pmMasterId,DATE_FORMAT(pmDate,'%d-%m-%Y') AS pmDate,pmmaster.incomingId,newPartyName,
		                      pmmaster.planningId,batchNo,logSheetId,pmmaster.processId,newProcessName,quantity,
		                      pmmaster.weight,pmmaster.materialId,materialName,DATE_FORMAT(startTime,'%H:%i') AS startTime,
		                      startTemperature,DATE_FORMAT(soakingStartTime,'%H:%i') AS soakingStartTime,
		                      soakingStartTemperature,soakingHour,soakingHourTemperature,
		                      DATE_FORMAT(endTime,'%H:%i') AS endTime,endTemperature,pmmaster.qMId,qMName,quenchingTime,tempBforQue,
		                      tempAfterQue,putExtraData,
		                      DATE_FORMAT(extraTempAttain,'%H:%i') AS extraTempAttain,extraTempAttainTemperature,
		                      DATE_FORMAT(extraSoaking,'%H:%i') AS extraSoaking,extraSoakingTemperature,
		                      DATE_FORMAT(extraOut,'%H:%i') AS extraOut,extraOutTemperature, notes,incoming.challan,column1,
		                      column2,column3,column4,column5,column6,partyName,processName
		                 FROM pmmaster
		                 JOIN incoming ON pmmaster.incomingId = incoming.incomingId
		                 JOIN party    ON incoming.partyId = party.partyId
		                 JOIN process  ON pmmaster.processId = process.processId
		                 JOIN material ON pmmaster.materialId = material.materialId
		                 JOIN quenchingmedia ON pmmaster.qMId = quenchingmedia.qMId
		                WHERE logSheetId = ".$_GET['logSheetId']."
		                  AND pmmaster.pmMasterId = ".$_GET['pmMasterId'];
    $selectDataRes = mysql_query($selectData);
    $logDataArray = array();
    if($logRow = mysql_fetch_array($selectDataRes))
    {
    	$logDataArray['pmMasterId']       = $logRow['pmMasterId'];
    	$logDataArray['logSheetId']       = $logRow['logSheetId'];
    	$logDataArray['incomingId']       = $logRow['incomingId'];
    	$logDataArray['planningId']       = $logRow['planningId'];
    	$logDataArray['batchNo']          = $logRow['batchNo'];
    	$logDataArray['processId']        = $logRow['processId'];
    	$logDataArray['pmDate']           = $logRow['pmDate'];
    	$logDataArray['startTime']        = $logRow['startTime'];
    	$logDataArray['startTemperature'] = $logRow['startTemperature'];
    	$logDataArray['soakingStartTime'] = $logRow['soakingStartTime'];
    	$logDataArray['soakingStartTemperature'] = $logRow['soakingStartTemperature'];
    	$logDataArray['soakingHour']      = $logRow['soakingHour'];
    	$logDataArray['soakingHourTemperature'] = $logRow['soakingHourTemperature'];
    	$logDataArray['endTime']          = $logRow['endTime'];
    	$logDataArray['endTemperature']   = $logRow['endTemperature'];
    	$logDataArray['qMId']             = $logRow['qMId'];
    	$logDataArray['qMName']           = $logRow['qMName'];
    	$logDataArray['quenchingTime']    = $logRow['quenchingTime'];
    	$logDataArray['tempBforQue']      = $logRow['tempBforQue'];
    	$logDataArray['tempAfterQue']     = $logRow['tempAfterQue'];

    	$logDataArray['putExtraData']     = $logRow['putExtraData'];
    	$logDataArray['extraTempAttain']  = $logRow['extraTempAttain'];
    	$logDataArray['extraTempAttainTemperature'] = $logRow['extraTempAttainTemperature'];
    	$logDataArray['extraSoaking']     = $logRow['extraSoaking'];
    	$logDataArray['extraSoakingTemperature'] = $logRow['extraSoakingTemperature'];
    	$logDataArray['extraOut']         = $logRow['extraOut'];
    	$logDataArray['extraOutTemperature']= $logRow['extraOutTemperature'];
    	
    	$logDataArray['incChallan']       = $logRow['challan'];
    	$logDataArray['materialId']       = $logRow['materialId'];
    	$logDataArray['materialName']     = $logRow['materialName'];
    	$logDataArray['column1']          = $logRow['column1'];
    	$logDataArray['column2']          = $logRow['column2'];
    	$logDataArray['column3']          = $logRow['column3'];
    	$logDataArray['column4']          = $logRow['column4'];
    	$logDataArray['column5']          = $logRow['column5'];
    	$logDataArray['column6']          = $logRow['column6'];
    	$logDataArray['quantity']         = $logRow['quantity'];
    	$logDataArray['weight']           = $logRow['weight'];
    	$logDataArray['partyName']        = $logRow['partyName'];
    	$logDataArray['newPartyName']     = $logRow['newPartyName'];
    	$logDataArray['processName']      = $logRow['processName'];
    	$logDataArray['newProcessName']   = $logRow['newProcessName'];
    	$logDataArray['notes']            = $logRow['notes'];
    	

    	$selPMDetailTwo = "SELECT * FROM pmdetailone WHERE pmMasterId = ".$_GET['pmMasterId'];
    	$selPMDetailTwoRes = mysql_query($selPMDetailTwo);
    	$incDtlArray = array();
    	$i = 0;
    	while($pmdDtlRow = mysql_fetch_array($selPMDetailTwoRes))
    	{
      	$incDtlArray[$i]['columns1'] = $pmdDtlRow['columns1'];
      	$incDtlArray[$i]['columns2'] = $pmdDtlRow['columns2'];
      	$incDtlArray[$i]['columns3'] = $pmdDtlRow['columns3'];
      	$incDtlArray[$i]['columns4'] = $pmdDtlRow['columns4'];
      	$incDtlArray[$i]['columns5'] = $pmdDtlRow['columns5'];
      	$incDtlArray[$i]['columns6'] = $pmdDtlRow['columns6'];
      	$i++;
    	}
    	
//    	$selINDetailTwo = "SELECT * FROM incomingdetail WHERE incomingId = ".$logRow['incomingId'];
//    	$selINDetailTwoRes = mysql_query($selINDetailTwo);
//    	$incDtlArray = array();
//    	$i = 0;
//    	while($indDtlRow = mysql_fetch_array($selINDetailTwoRes))
//    	{
//      	$incDtlArray[$i]['columns1'] = $indDtlRow['columns1'];
//      	$incDtlArray[$i]['columns2'] = $indDtlRow['columns2'];
//      	$incDtlArray[$i]['columns3'] = $indDtlRow['columns3'];
//      	$incDtlArray[$i]['columns4'] = $indDtlRow['columns4'];
//      	$incDtlArray[$i]['columns5'] = $indDtlRow['columns5'];
//      	$incDtlArray[$i]['columns6'] = $indDtlRow['columns6'];
//      	$i++;
//    	}
   
      $selPMDetailTwo = "SELECT DATE_FORMAT(detailTime,'%H:%i') AS detailTime, detailTemperature
                           FROM pmdetailtwo
                          WHERE pmMasterId = ".$logRow['pmMasterId'];
      $selPMDetailTwoRes = mysql_query($selPMDetailTwo);
      $dtlTwoArray = array();
      $k = 0;
      while($dtlTwo = mysql_fetch_array($selPMDetailTwoRes))
      {
      	$dtlTwoArray[$k]['detailTime'] = $dtlTwo['detailTime'];
      	$dtlTwoArray[$k]['detailTemperature'] = $dtlTwo['detailTemperature'];
      	$k++;
      }
    }
			
	}
	include("./bottom.php");
	$smarty->assign("logDataArray",$logDataArray);
	$smarty->assign("incDtlArray",$incDtlArray);
	$smarty->assign("dtlTwoArray",$dtlTwoArray);
	$smarty->display("pmPrint.tpl");
}
?>